// somehow don't know why this is different from the example program given
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <map>

using namespace std;

typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;

deque<int>  p[2];
char buf[5];

int trans(char c){
    if(c > '1' && c <= '9') return c - '0';
    else if(c == 'T')   return 10;
    else if(c == 'A')   return 1;
    else if(c == 'J')   return 11;
    else if(c == 'Q')   return 12;
    else if(c == 'K')   return 13;
    else return -1;
}

int getCover(int n){
    if(n == 1) n = 14;
    return (n > 10)?n-10:0;
}

int main(){
    while(true){
        p[0].clear();
        p[1].clear();
        cin >> buf;
        if(buf[0] == '#')   break;
        p[0].push_back(trans(buf[1]));
        for(int i=1;i<52;i++){
            cin >> buf;
            p[i&1].push_back(trans(buf[1]));
        }
        bool hFace = false;
        bool pnum = 1;
        int cover = 0;

        deque<int> s;
        s.push_back(p[pnum].back()); p[pnum].pop_back(); pnum = !pnum;
        while(true){
            // print stack to trace
//            printf(" Stack: "); for(int i=0;i<s.size();i++) cout << s[i] << " ";    cout << endl;
 //           printf(" -- p1: "); for(int i=0;i<p[0].size();i++) cout << p[0][i] << " ";    cout << endl;
  //          printf(" -- p2: "); for(int i=0;i<p[1].size();i++) cout << p[1][i] << " ";    cout << endl;
            if(getCover(s.back())){
                cover = getCover(s.back()) - 1;
                if(hFace)   pnum = !pnum;
                hFace = true;
                if(p[pnum].empty()) break;
                s.push_back(p[pnum].back()); p[pnum].pop_back();
            } else if(cover){
                cover--;
                if(p[pnum].empty()) break;
                s.push_back(p[pnum].back()); p[pnum].pop_back();
            } else if(hFace){
                pnum = !pnum;
                hFace = false;
                p[pnum].insert(p[pnum].begin(),s.begin(),s.end()); s.clear();
                s.push_back(p[pnum].back()); p[pnum].pop_back();
                pnum = !pnum;
            } else{
                if(p[pnum].empty()) break;
                s.push_back(p[pnum].back()); p[pnum].pop_back();
                pnum = !pnum;
            }
        }
        pnum = !pnum;
        printf("%d%3d\n",pnum+1,p[pnum].size());
    }
    return 0;
}
